package com.legendshop.openportal.sdk.service;

import com.legendshop.openportal.sdk.client.ClientExecutionParams;
import com.legendshop.openportal.sdk.client.OpenClient;
import com.legendshop.openportal.sdk.client.http.HttpResponseAnalyzerSupport;
import com.legendshop.openportal.sdk.client.http.HttpResponseHandler;
import com.legendshop.openportal.sdk.client.http.handler.DefaultHttpResponseHandler;
import com.legendshop.openportal.sdk.model.OpenResult;
import com.legendshop.openportal.sdk.model.request.AuthRequest;
import com.legendshop.openportal.sdk.model.response.AuthResponse;
import com.legendshop.openportal.sdk.registry.OpenClientRegistry;

/**
 * 开放平台认证服务
 * @author jzh
 * @version 1.0.0
 * @title AuthService
 * @date 2024/6/18 17:30
 * @description：
 */
public class AuthService {

    /**
     * 获取认证token
     * @param authRequest
     * @return
     */
    public static OpenResult<AuthResponse> getAccessToken(AuthRequest authRequest) {
        OpenClient openClient = OpenClientRegistry.getOpenClient();
        HttpResponseHandler<AuthResponse> responseHandler = new DefaultHttpResponseHandler<>(AuthResponse.class, HttpResponseAnalyzerSupport.getAnalyzerChain());
        return openClient.execute(new ClientExecutionParams<>(false, authRequest, responseHandler));
    }
}
